#!/usr/bin/env python3
# --*-- coding:UTF-8 --*--

# 用户输入数字
#num1 = input('输入第一个数字：')
#num2 = input('输入第二个数字：')

# 求和
#print("num %s and num %s equle %s " % (num1 ,num2 ,float(num1)+float(num2)))
#print("num {0} and num {1} euqle {2}".format(num1,num2,float(num1)+float(num2)))

#import re

#if re.match('www','www.baidu.com'):
#    print ("yes")
#else:
#    print ("no")

import pymysql

#connect database
db = pymysql.connect("192.168.0.191",'icms','qwe123','test')

#create cursor
cursor = db.cursor()

#execute queue sql
#cursor.execute("select version()")
sql = """ select * from employee"""


#get data
#data = cursor.fetchone()  #Only one result



#print data
#print ("Database Version: {0}".format(data))

try:
    cursor.execute(sql)
    results = cursor.fetchall()   #get all result
    for row in results:
        fname  = row[0]
        lname  = row[1]
        age    = row[2]
        sex    = row[3]
        income = row[4]
        print ("First name: {0},Last name: {1},age: {2},sex: {3},income: {4}"\
               .format(fname,lname,age,sex,income))
except:
    print ("Error:unable to fetch data")
    
#create table
#sql = """create table employee (
#        first_name char(20) not null,
#        last_name char(20) ,
#        age int,
#        sex char(1),
#        income float )"""

#cursor.execute(sql)

#execute insert sql
sql = """insert into employee (first_name ,last_name ,age,sex,income)
      values("Bman","RAl",28,"M",8000)"""

#try :
#    cursor.execute(sql)
#    db.commit()
#except:
#    db.rollback()




#close database
db.close
